# Copyright (C) 2009  Rob Britton
#
# This file is part of OORegress.
#
# OORegress is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

require 'java'
require 'jurt.jar'
require 'juh.jar'
require 'ridl.jar'
require 'unoil.jar'

def load_classes(*args)
  args.each do |a|
    include_class "com.sun.star." + a
  end
end

load_classes "uno.UnoRuntime",
  "comp.helper.Bootstrap"

class Class
  def query_uno(obj)
    UnoRuntime.queryInterface(self.java_class, obj)
  end
end

class Module
  def query_uno(obj)
    UnoRuntime.queryInterface(self.java_class, obj)
  end
end

module OpenOffice
  class Base
    def initialize
      begin
        @xRemoteContext = Bootstrap.bootstrap

        @xRemoteServiceManager = @xRemoteContext.getServiceManager
      rescue
        puts $!
        #puts $!.backtrace
        exit
      end

      @desktop = @xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", @xRemoteContext)
    end
  end
end
